﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using Common;

namespace Model
{
    /// <summary>
    /// 游戏配置
    /// </summary>
    public class GameConfig
    {
        private bool autoRadio30;
        private RadioType radio30Type;
        private bool autoRadio50;
        private RadioType radio50Type;
        private bool autoRadio70;
        private RadioType radio70Type;
        private bool autoRadio80;
        private RadioType radio80Type;
        private bool autoRadio90;
        private RadioType radio90Type;
        private bool autoDialyQuest;
        private bool autoExpQuest;
        private bool autoAttackMonster;
        private int monsterID;
        private bool autoGuaji=true;
        private RadioQuest radioQuestType=RadioQuest.Radio50;
        private ClientWindowState windowState = ClientWindowState.Close;
        private bool autoLogin = false;
        private ExpTaskColor needExpTaskColor=ExpTaskColor.蓝色;
        private bool onlyTask10 = true;

        /// <summary>
        /// 是否自动登录
        /// </summary>
        public bool AutoLogin
        {
            get { return autoLogin; }
            set { autoLogin = value; }
        }

        /// <summary>
        /// 登录成功后客户端窗口的状态
        /// </summary>
        public ClientWindowState WindowState
        {
            get { return windowState; }
            set { windowState = value; }
        }

        /// <summary>
        /// 要进行的副本任务
        /// </summary>
        public RadioQuest RadioQuestType
        {
            get { return radioQuestType; }
            set { radioQuestType = value; }
        }

        /// <summary>
        /// 自动游戏完成后进行自动打怪
        /// </summary>
        public bool AutoAttackMonster
        {
            get { return autoAttackMonster; }
            set { autoAttackMonster = value; }
        }

        /// <summary>
        /// 自动打怪的怪物编号
        /// </summary>
        public int MonsterID
        {
            get { return monsterID; }
            set { monsterID = value; }
        }

        /// <summary>
        /// 自动游戏完成后是否自动挂机
        /// </summary>
        public bool AutoGuaji
        {
            get { return autoGuaji; }
            set { autoGuaji = value; }
        }

        /// <summary>
        /// 是否自动老板娘银币任务
        /// </summary>
        public bool AutoDialyQuest
        {
            get { return autoDialyQuest; }
            set { autoDialyQuest = value; }
        }

        /// <summary>
        /// 是否自动循环经验任务
        /// </summary>
        public bool AutoExpQuest
        {
            get { return autoExpQuest; }
            set { autoExpQuest = value; }
        }

        /// <summary>
        /// 是否只做前10个循环经验任务
        /// </summary>
        public bool OnlyTask10
        {
            get { return onlyTask10; }
            set { onlyTask10 = value; }
        }

        /// <summary>
        /// 循环经验任务的最低颜色
        /// </summary>
        public ExpTaskColor NeedExpTaskColor
        {
            get { return needExpTaskColor; }
            set { needExpTaskColor = value; }
        }

        /// <summary>
        /// 是否自动30副本
        /// </summary>
        public bool AutoRadio30
        {
            get { return autoRadio30; }
            set { autoRadio30 = value; }
        }
        /// <summary>
        /// 自动30副本的难度
        /// </summary>
        public RadioType Radio30Type
        {
            get { return radio30Type; }
            set { radio30Type = value; }
        }

        /// <summary>
        /// 是否自动50副本
        /// </summary>
        public bool AutoRadio50
        {
            get { return autoRadio50; }
            set { autoRadio50 = value; }
        }
        /// <summary>
        /// 自动50副本的难度
        /// </summary>
        public RadioType Radio50Type
        {
            get { return radio50Type; }
            set { radio50Type = value; }
        }

        /// <summary>
        /// 是否自动70副本
        /// </summary>
        public bool AutoRadio70
        {
            get { return autoRadio70; }
            set { autoRadio70 = value; }
        }
        /// <summary>
        /// 自动70副本的难度
        /// </summary>
        public RadioType Radio70Type
        {
            get { return radio70Type; }
            set { radio70Type = value; }
        }

        /// <summary>
        /// 是否自动80副本
        /// </summary>
        public bool AutoRadio80
        {
            get { return autoRadio80; }
            set { autoRadio80 = value; }
        }
        /// <summary>
        /// 自动80副本的难度
        /// </summary>
        public RadioType Radio80Type
        {
            get { return radio80Type; }
            set { radio80Type = value; }
        }

        /// <summary>
        /// 是否自动90副本
        /// </summary>
        public bool AutoRadio90
        {
            get { return autoRadio90; }
            set { autoRadio90 = value; }
        }
        /// <summary>
        /// 自动90副本的难度
        /// </summary>
        public RadioType Radio90Type
        {
            get { return radio90Type; }
            set { radio90Type = value; }
        }

        public GameConfig()
        {

        }

        /// <summary>
        /// 保存配置信息
        /// </summary>
        /// <param name="account"></param>
        /// <returns>成功返回true否则返回false</returns>
        public bool Save(Account account)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + "//config//";
            try
            {
                using (FileStream stream = new FileStream(path + account.ToString("_") + "_config.xml", FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(GameConfig));
                    serializer.Serialize(stream, this);
                    stream.Close();
                }
                return true;
            }
            catch (Exception ex)
            {
                //日志记录
                Console.WriteLine("保存 "+account.ToString("_")+" 的配置信息时出错：");
                Tools.PrintException(ex);
            }
            return false;
        }
    }

    /// <summary>
    /// 副本任务枚举
    /// </summary>
    public enum RadioQuest
    {
        Radio30,
        Radio50,
        Radio70,
        Radio80
    }

    /// <summary>
    /// 登录成功后客户端窗口的状态
    /// </summary>
    public enum ClientWindowState
    {
        /// <summary>
        /// 显示
        /// </summary>
        Show,
        /// <summary>
        /// 隐藏
        /// </summary>
        Hide,
        /// <summary>
        /// 关闭
        /// </summary>
        Close
    }
}
